package me.kagami.autotesthelper;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class ReadMeDialog extends JDialog {
    private JPanel contentPane;
    private JButton buttonOK;
    private JTextPane textPane1;

    public ReadMeDialog() {
        String rd = "在使用前，需要在maven的pom文件中加入相关的依赖包，并且更新maven项目依赖，确保包正确的引入项目。\n" +
                "比如：\n" +
                "<dependency>\n" +
                "\t<groupId>com.xwbank.cmp</groupId>\n" +
                "\t<artifactId>cmp-route-api</artifactId>\n" +
                "\t<version>1.0.8.220920-SNAPSHOT</version>\n" +
                "</dependency>\n" +
                "\n" +
                "然后点击插件,className输入框支持两种使用方式\n" +
                "\n" +
                "1 直接输入类名，那么会生成这个类对应的yaml或者json，比如\n" +
                "com.xwbank.cmp.route.api.dto.route.RouteResultNoticeForApi\n" +
                "\n" +
                "2 直接输入类名方法名，那么会生成这个方法的入参对应的yaml或者json，比如\n" +
                "com.xwbank.cmp.route.api.service.CmpRouteQueryService#queryFusPercentage\n" +
                "\n";
        setContentPane(contentPane);
        setModal(true);
        getRootPane().setDefaultButton(buttonOK);
        Toolkit kit = Toolkit.getDefaultToolkit(); // 定义工具包
        Dimension screenSize = kit.getScreenSize(); // 获取屏幕的尺寸
        int screenWidth = screenSize.width / 2; // 获取屏幕的宽
        int screenHeight = screenSize.height / 2; // 获取屏幕的高
        int height = this.getHeight();
        int width = this.getWidth();
        setLocation(screenWidth - width / 2 - 300, screenHeight - height / 2 - 250);
        textPane1.setText(rd);
        buttonOK.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onOK();
            }
        });


        // call onCancel() when cross is clicked
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                onCancel();
            }
        });

        // call onCancel() on ESCAPE
        contentPane.registerKeyboardAction(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onCancel();
            }
        }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    }

    private void onOK() {
        // add your code here
        dispose();
    }

    private void onCancel() {
        // add your code here if necessary
        dispose();
    }

    public static void main(String[] args) {
        ReadMeDialog dialog = new ReadMeDialog();
        dialog.pack();
        dialog.setVisible(true);
        System.exit(0);
    }
}